package org.example.command;

import org.example.model.FarmMachine;

public class StartTaskCommand implements FarmMachineCommand {
    private FarmMachine machine;
    private boolean executed;

    public StartTaskCommand(FarmMachine machine) {
        this.machine = machine;
        this.executed = false;
    }

    @Override
    public void execute() {
        System.out.println("执行命令: 开始任务");
        machine.getState().handleEvent(machine, "开始任务");
        machine.getState().execute(machine);
        executed = true;
    }

    @Override
    public void undo() {
        if (executed) {
            System.out.println("撤销命令: 停止任务");
            machine.getState().handleEvent(machine, "任务完成");
            executed = false;
        }
    }

    @Override
    public String getCommandName() {
        return "开始任务";
    }
}
